<?php
$arguments = $_SERVER['REQUEST_URI'];

$arguments = explode("/", ltrim($arguments, "/"));

// No file specified? Off to index.
if(!$arguments[0]) $arguments[0] = "index";

// See if the file requested is legal
if(!preg_match("/^[a-z0-9]+$/i", $arguments[0])) {
	URL::show_404('The requested URL contained illegal characters');
}

$arguments[0] = dirname(__FILE__) . "/pages/" . $arguments[0] . '.php';

if(file_exists($arguments[0])) {
	Template::load("header");
	require($arguments[0]);	
	Template::load("footer");
}else{
	URL::show_404('The requested page could not be found');
}